package com.example.makerspace.dao;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.makerspace.domain.EnterpriseCertificationDO;
import com.example.makerspace.domain.EnterpriseDataDO;
import com.example.makerspace.dto.Pagination;
import com.example.makerspace.mapper.EnterpriseDataMapper;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class EnterpriseDataDAO extends BaseDAO<EnterpriseDataDO>{




    @Resource
    private EnterpriseDataMapper enterpriseDataMapper;



    @PostConstruct
    public void init(){
        this.mapper = enterpriseDataMapper;
    }


    public  void   bashInsert(List<EnterpriseDataDO> enterpriseDataDOList){
        for(EnterpriseDataDO enterpriseDataDO:enterpriseDataDOList){
            enterpriseDataMapper.insert(enterpriseDataDO);
        }

    }


    public IPage<EnterpriseDataDO> selectByPageByEntNameAndName(Pagination pagination, String name) {
        LambdaQueryWrapper<EnterpriseDataDO> qw = new LambdaQueryWrapper<EnterpriseDataDO>();
        qw.like(StringUtils.isNotEmpty(name),EnterpriseDataDO::getName,name).or()
                 .like(StringUtils.isNotEmpty(name),EnterpriseDataDO::getEnterpriseName,name).or()
                .like(StringUtils.isNotEmpty(name),EnterpriseDataDO::getPhone,name);
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),qw);
    }
}
